// Vita3K emulator project
// Copyright (C) 2024 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#pragma once

#include <util/types.h>

#define SCE_GXM_DEFAULT_UNIFORM_BUFFER_CONTAINER_INDEX 0
#define SCE_GXM_GPU_CORE_COUNT 4U
#define SCE_GXM_MAX_VERTEX_STREAMS 16
#define SCE_GXM_MAX_TEXTURE_UNITS 16
#define SCE_GXM_MAX_UNIFORM_BUFFERS 14
#define SCE_GXM_UNIFORM_BUFFER_OFFSET 1
#define SCE_GXM_REAL_MAX_UNIFORM_BUFFER (SCE_GXM_MAX_UNIFORM_BUFFERS + 1) // Include default
#define SCE_GXM_DEFAULT_UNIFORM_BUFFER 14
#define SCE_GXM_TEXTURE_BUFFER 15
#define SCE_GXM_LITERAL_BUFFER 16
#define SCE_GXM_THREAD_BUFFER 18
#define SCE_GXM_COLOR_BASE_FORMAT_MASK 0xF1800000U
#define SCE_GXM_COLOR_SWIZZLE_MASK 0x00300000U
#define SCE_GXM_TEXTURE_BASE_FORMAT_MASK 0x9F000000U
#define SCE_GXM_TEXTURE_SWIZZLE_MASK 0x00007000U
#define SCE_GXM_TILE_SHIFTX 5U
#define SCE_GXM_TILE_SHIFTY 5U
#define SCE_GXM_TILE_SIZEX (1U << SCE_GXM_TILE_SHIFTX)
#define SCE_GXM_TILE_SIZEY (1U << SCE_GXM_TILE_SHIFTY)
#define SCE_GXM_VISIBILITY_ALIGNMENT 16U

struct SceGxmProgramAttributeDescriptor;
struct SceGxmProgramParameter;
struct SceGxmSyncObject;
struct SceGxmPrecomputedVertexState;
struct SceGxmPrecomputedFragmentState;

enum SceGxmContextType {
    SCE_GXM_CONTEXT_TYPE_IMMEDIATE,
    SCE_GXM_CONTEXT_TYPE_DEFERRED
};

enum SceGxmColorMask : uint8_t {
    SCE_GXM_COLOR_MASK_NONE = 0,
    SCE_GXM_COLOR_MASK_A = (1 << 0),
    SCE_GXM_COLOR_MASK_R = (1 << 1),
    SCE_GXM_COLOR_MASK_G = (1 << 2),
    SCE_GXM_COLOR_MASK_B = (1 << 3),
    SCE_GXM_COLOR_MASK_ALL = (SCE_GXM_COLOR_MASK_A | SCE_GXM_COLOR_MASK_B | SCE_GXM_COLOR_MASK_G | SCE_GXM_COLOR_MASK_R)
};

enum SceGxmBlendFunc : uint8_t {
    SCE_GXM_BLEND_FUNC_NONE,
    SCE_GXM_BLEND_FUNC_ADD,
    SCE_GXM_BLEND_FUNC_SUBTRACT,
    SCE_GXM_BLEND_FUNC_REVERSE_SUBTRACT,
    SCE_GXM_BLEND_FUNC_MIN,
    SCE_GXM_BLEND_FUNC_MAX
};

enum SceGxmBlendFactor : uint8_t {
    SCE_GXM_BLEND_FACTOR_ZERO,
    SCE_GXM_BLEND_FACTOR_ONE,
    SCE_GXM_BLEND_FACTOR_SRC_COLOR,
    SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
    SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
    SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
    SCE_GXM_BLEND_FACTOR_DST_COLOR,
    SCE_GXM_BLEND_FACTOR_ONE_MINUS_DST_COLOR,
    SCE_GXM_BLEND_FACTOR_DST_ALPHA,
    SCE_GXM_BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
    SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE,
    SCE_GXM_BLEND_FACTOR_DST_ALPHA_SATURATE
};

enum SceGxmStencilFunc : uint32_t {
    SCE_GXM_STENCIL_FUNC_NEVER = 0x00000000u,
    SCE_GXM_STENCIL_FUNC_LESS = 0x02000000u,
    SCE_GXM_STENCIL_FUNC_EQUAL = 0x04000000u,
    SCE_GXM_STENCIL_FUNC_LESS_EQUAL = 0x06000000u,
    SCE_GXM_STENCIL_FUNC_GREATER = 0x08000000u,
    SCE_GXM_STENCIL_FUNC_NOT_EQUAL = 0x0A000000u,
    SCE_GXM_STENCIL_FUNC_GREATER_EQUAL = 0x0C000000u,
    SCE_GXM_STENCIL_FUNC_ALWAYS = 0x0E000000u
};

enum SceGxmStencilOp : uint32_t {
    SCE_GXM_STENCIL_OP_KEEP = 0x00000000u,
    SCE_GXM_STENCIL_OP_ZERO = 0x00000001u,
    SCE_GXM_STENCIL_OP_REPLACE = 0x00000002u,
    SCE_GXM_STENCIL_OP_INCR = 0x00000003u,
    SCE_GXM_STENCIL_OP_DECR = 0x00000004u,
    SCE_GXM_STENCIL_OP_INVERT = 0x00000005u,
    SCE_GXM_STENCIL_OP_INCR_WRAP = 0x00000006u,
    SCE_GXM_STENCIL_OP_DECR_WRAP = 0x00000007u
};

enum SceGxmViewportMode : uint32_t {
    SCE_GXM_VIEWPORT_DISABLED = 0x00010000u,
    SCE_GXM_VIEWPORT_ENABLED = 0x00000000u
};

enum SceGxmCullMode : uint32_t {
    SCE_GXM_CULL_NONE = 0x00000000u,
    SCE_GXM_CULL_CW = 0x00000001u,
    SCE_GXM_CULL_CCW = 0x00000002u
};

enum SceGxmPassType : uint32_t {
    SCE_GXM_PASS_TYPE_OPAQUE = 0x00000000u,
    SCE_GXM_PASS_TYPE_TRANSLUCENT = 0x02000000u,
    SCE_GXM_PASS_TYPE_DISCARD = 0x04000000u,
    SCE_GXM_PASS_TYPE_MASK_UPDATE = 0x06000000u,
    SCE_GXM_PASS_TYPE_DEPTH_REPLACE = 0x0A000000u
};

enum SceGxmRegionClipMode : uint32_t {
    SCE_GXM_REGION_CLIP_NONE = 0x00000000u,
    SCE_GXM_REGION_CLIP_ALL = 0x40000000u,
    SCE_GXM_REGION_CLIP_OUTSIDE = 0x80000000u,
    SCE_GXM_REGION_CLIP_INSIDE = 0xC0000000u
};

enum SceGxmTwoSidedMode : uint32_t {
    SCE_GXM_TWO_SIDED_DISABLED = 0x00000000u,
    SCE_GXM_TWO_SIDED_ENABLED = 0x00000800u
};

enum SceGxmDepthFunc : uint32_t {
    SCE_GXM_DEPTH_FUNC_NEVER = 0x00000000u,
    SCE_GXM_DEPTH_FUNC_LESS = 0x00400000u,
    SCE_GXM_DEPTH_FUNC_EQUAL = 0x00800000u,
    SCE_GXM_DEPTH_FUNC_LESS_EQUAL = 0x00C00000u,
    SCE_GXM_DEPTH_FUNC_GREATER = 0x01000000u,
    SCE_GXM_DEPTH_FUNC_NOT_EQUAL = 0x01400000u,
    SCE_GXM_DEPTH_FUNC_GREATER_EQUAL = 0x01800000u,
    SCE_GXM_DEPTH_FUNC_ALWAYS = 0x01C00000u
};

enum SceGxmDepthWriteMode : uint32_t {
    SCE_GXM_DEPTH_WRITE_DISABLED = 0x00100000u,
    SCE_GXM_DEPTH_WRITE_ENABLED = 0x00000000u
};

enum SceGxmPolygonMode : uint32_t {
    SCE_GXM_POLYGON_MODE_TRIANGLE_FILL = 0x00000000u,
    SCE_GXM_POLYGON_MODE_LINE = 0x00008000u,
    SCE_GXM_POLYGON_MODE_POINT_10UV = 0x00010000u,
    SCE_GXM_POLYGON_MODE_POINT = 0x00018000u,
    SCE_GXM_POLYGON_MODE_POINT_01UV = 0x00020000u,
    SCE_GXM_POLYGON_MODE_TRIANGLE_LINE = 0x00028000u,
    SCE_GXM_POLYGON_MODE_TRIANGLE_POINT = 0x00030000u
};

enum SceGxmPrimitiveType : uint32_t {
    SCE_GXM_PRIMITIVE_TRIANGLES = 0x00000000u,
    SCE_GXM_PRIMITIVE_LINES = 0x04000000u,
    SCE_GXM_PRIMITIVE_POINTS = 0x08000000u,
    SCE_GXM_PRIMITIVE_TRIANGLE_STRIP = 0x0C000000u,
    SCE_GXM_PRIMITIVE_TRIANGLE_FAN = 0x10000000u,
    SCE_GXM_PRIMITIVE_TRIANGLE_EDGES = 0x14000000u
};

enum SceGxmDepthStencilFormat : uint32_t {
    SCE_GXM_DEPTH_STENCIL_FORMAT_DF32 = 0x00044000u,
    SCE_GXM_DEPTH_STENCIL_FORMAT_S8 = 0x00022000u,
    SCE_GXM_DEPTH_STENCIL_FORMAT_DF32_S8 = 0x00066000u,
    SCE_GXM_DEPTH_STENCIL_FORMAT_DF32M = 0x000CC000U,
    SCE_GXM_DEPTH_STENCIL_FORMAT_DF32M_S8 = 0x000EE000U,
    SCE_GXM_DEPTH_STENCIL_FORMAT_S8D24 = 0x01266000u,
    SCE_GXM_DEPTH_STENCIL_FORMAT_D16 = 0x02444000u
};

enum SceGxmIndexFormat : uint32_t {
    SCE_GXM_INDEX_FORMAT_U16 = 0x00000000u,
    SCE_GXM_INDEX_FORMAT_U32 = 0x01000000u
};

enum SceGxmFragmentProgramMode : uint32_t {
    SCE_GXM_FRAGMENT_PROGRAM_DISABLED = 0x00200000u,
    SCE_GXM_FRAGMENT_PROGRAM_ENABLED = 0x00000000u
};

enum SceGxmLineFillLastPixelMode : uint32_t {
    SCE_GXM_LINE_FILL_LAST_PIXEL_DISABLED = 0x00000000u,
    SCE_GXM_LINE_FILL_LAST_PIXEL_ENABLED = 0x00080000u
};

enum SceGxmParameterCategory : uint8_t {
    SCE_GXM_PARAMETER_CATEGORY_ATTRIBUTE,
    SCE_GXM_PARAMETER_CATEGORY_UNIFORM,
    SCE_GXM_PARAMETER_CATEGORY_SAMPLER,
    SCE_GXM_PARAMETER_CATEGORY_AUXILIARY_SURFACE,
    SCE_GXM_PARAMETER_CATEGORY_UNIFORM_BUFFER
};

enum SceGxmParameterType : uint8_t {
    SCE_GXM_PARAMETER_TYPE_F32,
    SCE_GXM_PARAMETER_TYPE_F16,
    SCE_GXM_PARAMETER_TYPE_C10,
    SCE_GXM_PARAMETER_TYPE_U32,
    SCE_GXM_PARAMETER_TYPE_S32,
    SCE_GXM_PARAMETER_TYPE_U16,
    SCE_GXM_PARAMETER_TYPE_S16,
    SCE_GXM_PARAMETER_TYPE_U8,
    SCE_GXM_PARAMETER_TYPE_S8,
    SCE_GXM_PARAMETER_TYPE_AGGREGATE
};

enum SceGxmParameterSemantic : uint8_t {
    SCE_GXM_PARAMETER_SEMANTIC_NONE,
    SCE_GXM_PARAMETER_SEMANTIC_ATTR,
    SCE_GXM_PARAMETER_SEMANTIC_BCOL,
    SCE_GXM_PARAMETER_SEMANTIC_BINORMAL,
    SCE_GXM_PARAMETER_SEMANTIC_BLENDINDICES,
    SCE_GXM_PARAMETER_SEMANTIC_BLENDWEIGHT,
    SCE_GXM_PARAMETER_SEMANTIC_COLOR,
    SCE_GXM_PARAMETER_SEMANTIC_DIFFUSE,
    SCE_GXM_PARAMETER_SEMANTIC_FOGCOORD,
    SCE_GXM_PARAMETER_SEMANTIC_NORMAL,
    SCE_GXM_PARAMETER_SEMANTIC_POINTSIZE,
    SCE_GXM_PARAMETER_SEMANTIC_POSITION,
    SCE_GXM_PARAMETER_SEMANTIC_SPECULAR,
    SCE_GXM_PARAMETER_SEMANTIC_TANGENT,
    SCE_GXM_PARAMETER_SEMANTIC_TEXCOORD,
    SCE_GXM_PARAMETER_SEMANTIC_INDEX,
    SCE_GXM_PARAMETER_SEMANTIC_INSTANCE
};

enum SceGxmTextureType : uint32_t {
    SCE_GXM_TEXTURE_SWIZZLED = 0x00000000u,
    SCE_GXM_TEXTURE_CUBE = 0x40000000u,
    SCE_GXM_TEXTURE_LINEAR = 0x60000000u,
    SCE_GXM_TEXTURE_TILED = 0x80000000u,
    SCE_GXM_TEXTURE_SWIZZLED_ARBITRARY = 0xA0000000U,
    SCE_GXM_TEXTURE_LINEAR_STRIDED = 0xC0000000u,
    SCE_GXM_TEXTURE_CUBE_ARBITRARY = 0xE0000000U
};

enum SceGxmTextureSwizzle4Mode : uint32_t {
    SCE_GXM_TEXTURE_SWIZZLE4_ABGR = 0x00000000u,
    SCE_GXM_TEXTURE_SWIZZLE4_ARGB = 0x00001000u,
    SCE_GXM_TEXTURE_SWIZZLE4_RGBA = 0x00002000u,
    SCE_GXM_TEXTURE_SWIZZLE4_BGRA = 0x00003000u,
    SCE_GXM_TEXTURE_SWIZZLE4_1BGR = 0x00004000u,
    SCE_GXM_TEXTURE_SWIZZLE4_1RGB = 0x00005000u,
    SCE_GXM_TEXTURE_SWIZZLE4_RGB1 = 0x00006000u,
    SCE_GXM_TEXTURE_SWIZZLE4_BGR1 = 0x00007000u
};

enum SceGxmTextureSwizzle3Mode : uint32_t {
    SCE_GXM_TEXTURE_SWIZZLE3_BGR = 0x00000000u,
    SCE_GXM_TEXTURE_SWIZZLE3_RGB = 0x00001000u
};

enum SceGxmTextureSwizzle2Mode : uint32_t {
    SCE_GXM_TEXTURE_SWIZZLE2_GR = 0x00000000u,
    SCE_GXM_TEXTURE_SWIZZLE2_00GR = 0x00001000u,
    SCE_GXM_TEXTURE_SWIZZLE2_GRRR = 0x00002000u,
    SCE_GXM_TEXTURE_SWIZZLE2_RGGG = 0x00003000u,
    SCE_GXM_TEXTURE_SWIZZLE2_GRGR = 0x00004000u,
    SCE_GXM_TEXTURE_SWIZZLE2_00RG = 0x00005000u
};

enum SceGxmTextureSwizzle2ModeAlt : uint32_t {
    SCE_GXM_TEXTURE_SWIZZLE2_SD = 0x00000000u,
    SCE_GXM_TEXTURE_SWIZZLE2_DS = 0x00001000u
};

enum SceGxmTextureSwizzle1Mode : uint32_t {
    SCE_GXM_TEXTURE_SWIZZLE1_R = 0x00000000u,
    SCE_GXM_TEXTURE_SWIZZLE1_000R = 0x00001000u,
    SCE_GXM_TEXTURE_SWIZZLE1_111R = 0x00002000u,
    SCE_GXM_TEXTURE_SWIZZLE1_RRRR = 0x00003000u,
    SCE_GXM_TEXTURE_SWIZZLE1_0RRR = 0x00004000u,
    SCE_GXM_TEXTURE_SWIZZLE1_1RRR = 0x00005000u,
    SCE_GXM_TEXTURE_SWIZZLE1_R000 = 0x00006000u,
    SCE_GXM_TEXTURE_SWIZZLE1_R111 = 0x00007000u
};

enum SceGxmTextureSwizzleYUV422Mode : uint32_t {
    SCE_GXM_TEXTURE_SWIZZLE_YUYV_CSC0 = 0x00000000u,
    SCE_GXM_TEXTURE_SWIZZLE_YVYU_CSC0 = 0x00001000u,
    SCE_GXM_TEXTURE_SWIZZLE_UYVY_CSC0 = 0x00002000u,
    SCE_GXM_TEXTURE_SWIZZLE_VYUY_CSC0 = 0x00003000u,
    SCE_GXM_TEXTURE_SWIZZLE_YUYV_CSC1 = 0x00004000u,
    SCE_GXM_TEXTURE_SWIZZLE_YVYU_CSC1 = 0x00005000u,
    SCE_GXM_TEXTURE_SWIZZLE_UYVY_CSC1 = 0x00006000u,
    SCE_GXM_TEXTURE_SWIZZLE_VYUY_CSC1 = 0x00007000u
};

enum SceGxmTextureSwizzleYUV420Mode : uint32_t {
    SCE_GXM_TEXTURE_SWIZZLE_YUV_CSC0 = 0x00000000u,
    SCE_GXM_TEXTURE_SWIZZLE_YVU_CSC0 = 0x00001000u,
    SCE_GXM_TEXTURE_SWIZZLE_YUV_CSC1 = 0x00002000u,
    SCE_GXM_TEXTURE_SWIZZLE_YVU_CSC1 = 0x00003000u
};

enum SceGxmTextureFilter : uint32_t {
    SCE_GXM_TEXTURE_FILTER_POINT = 0x00000000u,
    SCE_GXM_TEXTURE_FILTER_LINEAR = 0x00000001u,
    SCE_GXM_TEXTURE_FILTER_MIPMAP_LINEAR = 0x00000002u,
    SCE_GXM_TEXTURE_FILTER_MIPMAP_POINT = 0x00000003u
};

enum SceGxmTextureMipFilter : uint32_t {
    SCE_GXM_TEXTURE_MIP_FILTER_DISABLED = 0x00000000u,
    SCE_GXM_TEXTURE_MIP_FILTER_ENABLED = 0x00000200u
};

enum SceGxmTextureAddrMode : uint32_t {
    SCE_GXM_TEXTURE_ADDR_REPEAT = 0x00000000u,
    SCE_GXM_TEXTURE_ADDR_MIRROR = 0x00000001u,
    SCE_GXM_TEXTURE_ADDR_CLAMP = 0x00000002u,
    SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP = 0x00000003u,
    SCE_GXM_TEXTURE_ADDR_REPEAT_IGNORE_BORDER = 0x00000004u,
    SCE_GXM_TEXTURE_ADDR_CLAMP_FULL_BORDER = 0x00000005u,
    SCE_GXM_TEXTURE_ADDR_CLAMP_IGNORE_BORDER = 0x00000006u,
    SCE_GXM_TEXTURE_ADDR_CLAMP_HALF_BORDER = 0x00000007u
};

enum SceGxmMultisampleMode : uint16_t {
    SCE_GXM_MULTISAMPLE_NONE,
    SCE_GXM_MULTISAMPLE_2X,
    SCE_GXM_MULTISAMPLE_4X
};

enum SceGxmRenderTargetFlags : uint32_t {
    SCE_GXM_RENDER_TARGET_CUSTOM_MULTISAMPLE_LOCATIONS = 0x00000001U,
    SCE_GXM_RENDER_TARGET_MACROTILE_SYNC = 0x00000002U,
    SCE_GXM_RENDER_TARGET_USE_DISPLAY_QUEUE_PARAMS = 0x00000010U
};

struct SceGxmRenderTargetParams {
    uint32_t flags;
    uint16_t width;
    uint16_t height;
    uint16_t scenesPerFrame;
    SceGxmMultisampleMode multisampleMode;
    uint32_t multisampleLocations;
    SceUID driverMemBlock;
};

enum SceGxmTextureBaseFormat : uint32_t {
    SCE_GXM_TEXTURE_BASE_FORMAT_U8 = 0x00000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S8 = 0x01000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 = 0x02000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U8U3U3U2 = 0x03000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 = 0x04000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U5U6U5 = 0x05000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S5S5U6 = 0x06000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U8U8 = 0x07000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S8S8 = 0x08000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U16 = 0x09000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S16 = 0x0A000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_F16 = 0x0B000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 = 0x0C000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 = 0x0D000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 = 0x0E000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U16U16 = 0x0F000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S16S16 = 0x10000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_F16F16 = 0x11000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_F32 = 0x12000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_F32M = 0x13000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_X8S8S8U8 = 0x14000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_X8U24 = 0x15000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U32 = 0x17000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S32 = 0x18000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_SE5M9M9M9 = 0x19000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_F11F11F10 = 0x1A000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 = 0x1B000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 = 0x1C000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 = 0x1D000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_F32F32 = 0x1E000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U32U32 = 0x1F000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_PVRT2BPP = 0x80000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_PVRT4BPP = 0x81000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_PVRTII2BPP = 0x82000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_PVRTII4BPP = 0x83000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_UBC1 = 0x85000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_UBC2 = 0x86000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_UBC3 = 0x87000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 = 0x88000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 = 0x89000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_UBC5 = 0x8A000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_SBC5 = 0x8B000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P2 = 0x90000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P3 = 0x91000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 = 0x92000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_P4 = 0x94000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_P8 = 0x95000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8 = 0x98000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8 = 0x99000000,
    SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 = 0x9A000000,

    // Fake formats, these format are not defined nor supported on a real PS Vita
    // They are defined and used here for texture replacement: a replaced texture
    // can use the following formats
    SCE_GXM_TEXTURE_BASE_FORMAT_UBC6H = 0xFF000001,
    SCE_GXM_TEXTURE_BASE_FORMAT_SBC6H = 0xFF000002,
    SCE_GXM_TEXTURE_BASE_FORMAT_UBC7 = 0xFF000003,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC4x4 = 0xFF000004,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC5x4 = 0xFF000005,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC5x5 = 0xFF000006,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC6x5 = 0xFF000007,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC6x6 = 0xFF000008,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC8x5 = 0xFF000009,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC8x6 = 0xFF00000A,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC8x8 = 0xFF00000B,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC10x5 = 0xFF00000C,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC10x6 = 0xFF00000D,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC10x8 = 0xFF00000E,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC10x10 = 0xFF00000F,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC12x10 = 0xFF000010,
    SCE_GXM_TEXTURE_BASE_FORMAT_ASTC12x12 = 0xFF000011,
};

template <typename T>
constexpr static inline uint32_t operator|(const SceGxmTextureBaseFormat a, const T b) {
    return static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
};

enum SceGxmTextureFormat : uint32_t {
    // Supported formats

    SCE_GXM_TEXTURE_FORMAT_U8_000R = SCE_GXM_TEXTURE_BASE_FORMAT_U8 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_U8_111R = SCE_GXM_TEXTURE_BASE_FORMAT_U8 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_U8_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_U8 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_U8_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_U8 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_U8_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_U8 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_U8_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_U8 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_U8_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_U8 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_U8_R = SCE_GXM_TEXTURE_BASE_FORMAT_U8 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_S8_000R = SCE_GXM_TEXTURE_BASE_FORMAT_S8 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_S8_111R = SCE_GXM_TEXTURE_BASE_FORMAT_S8 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_S8_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_S8 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_S8_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_S8 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_S8_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_S8 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_S8_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_S8 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_S8_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_S8 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_S8_R = SCE_GXM_TEXTURE_BASE_FORMAT_S8 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_U4U4U4U4_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_U4U4U4U4_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_U4U4U4U4_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_U4U4U4U4_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X4U4U4U4_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X4U4U4U4_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_U4U4U4X4_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_U4U4U4X4_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_U4U4U4U4 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_U8U3U3U2_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_U8U3U3U2,

    SCE_GXM_TEXTURE_FORMAT_U1U5U5U5_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_U1U5U5U5_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_U5U5U5U1_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_U5U5U5U1_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X1U5U5U5_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X1U5U5U5_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_U5U5U5X1_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_U5U5U5X1_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_U1U5U5U5 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_U5U6U5_BGR = SCE_GXM_TEXTURE_BASE_FORMAT_U5U6U5 | SCE_GXM_TEXTURE_SWIZZLE3_BGR,
    SCE_GXM_TEXTURE_FORMAT_U5U6U5_RGB = SCE_GXM_TEXTURE_BASE_FORMAT_U5U6U5 | SCE_GXM_TEXTURE_SWIZZLE3_RGB,

    SCE_GXM_TEXTURE_FORMAT_U6S5S5_BGR = SCE_GXM_TEXTURE_BASE_FORMAT_S5S5U6 | SCE_GXM_TEXTURE_SWIZZLE3_BGR,
    SCE_GXM_TEXTURE_FORMAT_S5S5U6_RGB = SCE_GXM_TEXTURE_BASE_FORMAT_S5S5U6 | SCE_GXM_TEXTURE_SWIZZLE3_RGB,

    SCE_GXM_TEXTURE_FORMAT_U8U8_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_U8U8_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_U8U8_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_U8U8_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_U8U8_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_U8U8_GR = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_S8S8_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_S8S8_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_S8S8_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_S8S8_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_S8S8_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_S8S8_GR = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_U16_000R = SCE_GXM_TEXTURE_BASE_FORMAT_U16 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_U16_111R = SCE_GXM_TEXTURE_BASE_FORMAT_U16 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_U16_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_U16 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_U16_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_U16 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_U16_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_U16 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_U16_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_U16 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_U16_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_U16 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_U16_R = SCE_GXM_TEXTURE_BASE_FORMAT_U16 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_S16_000R = SCE_GXM_TEXTURE_BASE_FORMAT_S16 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_S16_111R = SCE_GXM_TEXTURE_BASE_FORMAT_S16 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_S16_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_S16 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_S16_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_S16 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_S16_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_S16 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_S16_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_S16 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_S16_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_S16 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_S16_R = SCE_GXM_TEXTURE_BASE_FORMAT_S16 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_F16_000R = SCE_GXM_TEXTURE_BASE_FORMAT_F16 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_F16_111R = SCE_GXM_TEXTURE_BASE_FORMAT_F16 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_F16_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_F16 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_F16_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_F16 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_F16_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_F16 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_F16_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_F16 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_F16_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_F16 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_F16_R = SCE_GXM_TEXTURE_BASE_FORMAT_F16 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_U8U8U8X8_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_U8U8U8X8_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_S8S8S8S8_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_S8S8S8S8_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_S8S8S8S8_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_S8S8S8S8_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X8S8S8S8_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X8S8S8S8_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_S8S8S8X8_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_S8S8S8X8_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_U2U10U10U10_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_U2U10U10U10_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_U10U10U10U2_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_U10U10U10U2_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X2U10U10U10_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X2U10U10U10_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_U10U10U10X2_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_U10U10U10X2_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_U2U10U10U10 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_U16U16_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_U16U16_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_U16U16_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_U16U16_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_U16U16_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_U16U16_GR = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_S16S16_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_S16S16_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_S16S16_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_S16S16_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_S16S16_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_S16S16_GR = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_F16F16_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_F16F16_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_F16F16_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_F16F16_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_F16F16_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_F16F16_GR = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_F32_000R = SCE_GXM_TEXTURE_BASE_FORMAT_F32 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_F32_111R = SCE_GXM_TEXTURE_BASE_FORMAT_F32 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_F32_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_F32 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_F32_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_F32 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_F32_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_F32 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_F32_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_F32 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_F32_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_F32 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_F32_R = SCE_GXM_TEXTURE_BASE_FORMAT_F32 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_F32M_000R = SCE_GXM_TEXTURE_BASE_FORMAT_F32M | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_F32M_111R = SCE_GXM_TEXTURE_BASE_FORMAT_F32M | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_F32M_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_F32M | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_F32M_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_F32M | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_F32M_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_F32M | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_F32M_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_F32M | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_F32M_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_F32M | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_F32M_R = SCE_GXM_TEXTURE_BASE_FORMAT_F32M | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_X8S8S8U8_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_X8S8S8U8 | SCE_GXM_TEXTURE_SWIZZLE3_BGR,
    SCE_GXM_TEXTURE_FORMAT_X8U8S8S8_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_X8S8S8U8 | SCE_GXM_TEXTURE_SWIZZLE3_RGB,

    SCE_GXM_TEXTURE_FORMAT_X8U24_SD = SCE_GXM_TEXTURE_BASE_FORMAT_X8U24 | SCE_GXM_TEXTURE_SWIZZLE2_SD,
    SCE_GXM_TEXTURE_FORMAT_U24X8_DS = SCE_GXM_TEXTURE_BASE_FORMAT_X8U24 | SCE_GXM_TEXTURE_SWIZZLE2_DS,

    SCE_GXM_TEXTURE_FORMAT_U32_000R = SCE_GXM_TEXTURE_BASE_FORMAT_U32 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_U32_111R = SCE_GXM_TEXTURE_BASE_FORMAT_U32 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_U32_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_U32 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_U32_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_U32 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_U32_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_U32 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_U32_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_U32 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_U32_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_U32 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_U32_R = SCE_GXM_TEXTURE_BASE_FORMAT_U32 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_S32_000R = SCE_GXM_TEXTURE_BASE_FORMAT_S32 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_S32_111R = SCE_GXM_TEXTURE_BASE_FORMAT_S32 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_S32_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_S32 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_S32_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_S32 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_S32_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_S32 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_S32_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_S32 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_S32_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_S32 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_S32_R = SCE_GXM_TEXTURE_BASE_FORMAT_S32 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_SE5M9M9M9_BGR = SCE_GXM_TEXTURE_BASE_FORMAT_SE5M9M9M9 | SCE_GXM_TEXTURE_SWIZZLE3_BGR,
    SCE_GXM_TEXTURE_FORMAT_SE5M9M9M9_RGB = SCE_GXM_TEXTURE_BASE_FORMAT_SE5M9M9M9 | SCE_GXM_TEXTURE_SWIZZLE3_RGB,

    SCE_GXM_TEXTURE_FORMAT_F10F11F11_BGR = SCE_GXM_TEXTURE_BASE_FORMAT_F11F11F10 | SCE_GXM_TEXTURE_SWIZZLE3_BGR,
    SCE_GXM_TEXTURE_FORMAT_F11F11F10_RGB = SCE_GXM_TEXTURE_BASE_FORMAT_F11F11F10 | SCE_GXM_TEXTURE_SWIZZLE3_RGB,

    SCE_GXM_TEXTURE_FORMAT_F16F16F16F16_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_F16F16F16F16_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_F16F16F16F16_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_F16F16F16F16_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X16F16F16F16_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X16F16F16F16_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_F16F16F16X16_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_F16F16F16X16_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_F16F16F16F16 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_U16U16U16U16_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_U16U16U16U16_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_U16U16U16U16_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_U16U16U16U16_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X16U16U16U16_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X16U16U16U16_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_U16U16U16X16_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_U16U16U16X16_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_U16U16U16U16 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_S16S16S16S16_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_S16S16S16S16_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_S16S16S16S16_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_S16S16S16S16_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X16S16S16S16_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X16S16S16S16_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_S16S16S16X16_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_S16S16S16X16_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_S16S16S16S16 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_F32F32_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_F32F32 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_F32F32_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_F32F32 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_F32F32_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_F32F32 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_F32F32_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_F32F32 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_F32F32_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_F32F32 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_F32F32_GR = SCE_GXM_TEXTURE_BASE_FORMAT_F32F32 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_U32U32_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_U32U32 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_U32U32_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_U32U32 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_U32U32_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_U32U32 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_U32U32_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_U32U32 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_U32U32_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_U32U32 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_U32U32_GR = SCE_GXM_TEXTURE_BASE_FORMAT_U32U32 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_PVRT2BPP_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_PVRT2BPP | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_PVRT2BPP_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_PVRT2BPP | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,

    SCE_GXM_TEXTURE_FORMAT_PVRT4BPP_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_PVRT4BPP | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_PVRT4BPP_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_PVRT4BPP | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,

    SCE_GXM_TEXTURE_FORMAT_PVRTII2BPP_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_PVRTII2BPP | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_PVRTII2BPP_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_PVRTII2BPP | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,

    SCE_GXM_TEXTURE_FORMAT_PVRTII4BPP_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_PVRTII4BPP | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_PVRTII4BPP_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_PVRTII4BPP | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,

    SCE_GXM_TEXTURE_FORMAT_UBC1_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC1 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_UBC1_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC1 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,

    SCE_GXM_TEXTURE_FORMAT_UBC2_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC2 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_UBC2_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC2 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,

    SCE_GXM_TEXTURE_FORMAT_UBC3_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC3 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_UBC3_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC3 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,

    SCE_GXM_TEXTURE_FORMAT_UBC4_000R = SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_UBC4_111R = SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_UBC4_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_UBC4_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_UBC4_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_UBC4_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_UBC4_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_UBC4_R = SCE_GXM_TEXTURE_BASE_FORMAT_UBC4 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_SBC4_000R = SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 | SCE_GXM_TEXTURE_SWIZZLE1_000R,
    SCE_GXM_TEXTURE_FORMAT_SBC4_111R = SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 | SCE_GXM_TEXTURE_SWIZZLE1_111R,
    SCE_GXM_TEXTURE_FORMAT_SBC4_RRRR = SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 | SCE_GXM_TEXTURE_SWIZZLE1_RRRR,
    SCE_GXM_TEXTURE_FORMAT_SBC4_0RRR = SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 | SCE_GXM_TEXTURE_SWIZZLE1_0RRR,
    SCE_GXM_TEXTURE_FORMAT_SBC4_1RRR = SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 | SCE_GXM_TEXTURE_SWIZZLE1_1RRR,
    SCE_GXM_TEXTURE_FORMAT_SBC4_R000 = SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 | SCE_GXM_TEXTURE_SWIZZLE1_R000,
    SCE_GXM_TEXTURE_FORMAT_SBC4_R111 = SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 | SCE_GXM_TEXTURE_SWIZZLE1_R111,
    SCE_GXM_TEXTURE_FORMAT_SBC4_R = SCE_GXM_TEXTURE_BASE_FORMAT_SBC4 | SCE_GXM_TEXTURE_SWIZZLE1_R,

    SCE_GXM_TEXTURE_FORMAT_UBC5_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC5 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_UBC5_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC5 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_UBC5_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_UBC5 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_UBC5_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC5 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_UBC5_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_UBC5 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_UBC5_GR = SCE_GXM_TEXTURE_BASE_FORMAT_UBC5 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_SBC5_00GR = SCE_GXM_TEXTURE_BASE_FORMAT_SBC5 | SCE_GXM_TEXTURE_SWIZZLE2_00GR,
    SCE_GXM_TEXTURE_FORMAT_SBC5_GRRR = SCE_GXM_TEXTURE_BASE_FORMAT_SBC5 | SCE_GXM_TEXTURE_SWIZZLE2_GRRR,
    SCE_GXM_TEXTURE_FORMAT_SBC5_RGGG = SCE_GXM_TEXTURE_BASE_FORMAT_SBC5 | SCE_GXM_TEXTURE_SWIZZLE2_RGGG,
    SCE_GXM_TEXTURE_FORMAT_SBC5_GRGR = SCE_GXM_TEXTURE_BASE_FORMAT_SBC5 | SCE_GXM_TEXTURE_SWIZZLE2_GRGR,
    SCE_GXM_TEXTURE_FORMAT_SBC5_00RG = SCE_GXM_TEXTURE_BASE_FORMAT_SBC5 | SCE_GXM_TEXTURE_SWIZZLE2_00RG,
    SCE_GXM_TEXTURE_FORMAT_SBC5_GR = SCE_GXM_TEXTURE_BASE_FORMAT_SBC5 | SCE_GXM_TEXTURE_SWIZZLE2_GR,

    SCE_GXM_TEXTURE_FORMAT_YUV420P2_CSC0 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P2 | SCE_GXM_TEXTURE_SWIZZLE_YUV_CSC0,
    SCE_GXM_TEXTURE_FORMAT_YVU420P2_CSC0 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P2 | SCE_GXM_TEXTURE_SWIZZLE_YVU_CSC0,
    SCE_GXM_TEXTURE_FORMAT_YUV420P2_CSC1 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P2 | SCE_GXM_TEXTURE_SWIZZLE_YUV_CSC1,
    SCE_GXM_TEXTURE_FORMAT_YVU420P2_CSC1 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P2 | SCE_GXM_TEXTURE_SWIZZLE_YVU_CSC1,

    SCE_GXM_TEXTURE_FORMAT_YUV420P3_CSC0 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P3 | SCE_GXM_TEXTURE_SWIZZLE_YUV_CSC0,
    SCE_GXM_TEXTURE_FORMAT_YVU420P3_CSC0 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P3 | SCE_GXM_TEXTURE_SWIZZLE_YVU_CSC0,
    SCE_GXM_TEXTURE_FORMAT_YUV420P3_CSC1 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P3 | SCE_GXM_TEXTURE_SWIZZLE_YUV_CSC1,
    SCE_GXM_TEXTURE_FORMAT_YVU420P3_CSC1 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV420P3 | SCE_GXM_TEXTURE_SWIZZLE_YVU_CSC1,

    SCE_GXM_TEXTURE_FORMAT_YUYV422_CSC0 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 | SCE_GXM_TEXTURE_SWIZZLE_YUYV_CSC0,
    SCE_GXM_TEXTURE_FORMAT_YVYU422_CSC0 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 | SCE_GXM_TEXTURE_SWIZZLE_YVYU_CSC0,
    SCE_GXM_TEXTURE_FORMAT_UYVY422_CSC0 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 | SCE_GXM_TEXTURE_SWIZZLE_UYVY_CSC0,
    SCE_GXM_TEXTURE_FORMAT_VYUY422_CSC0 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 | SCE_GXM_TEXTURE_SWIZZLE_VYUY_CSC0,
    SCE_GXM_TEXTURE_FORMAT_YUYV422_CSC1 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 | SCE_GXM_TEXTURE_SWIZZLE_YUYV_CSC1,
    SCE_GXM_TEXTURE_FORMAT_YVYU422_CSC1 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 | SCE_GXM_TEXTURE_SWIZZLE_YVYU_CSC1,
    SCE_GXM_TEXTURE_FORMAT_UYVY422_CSC1 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 | SCE_GXM_TEXTURE_SWIZZLE_UYVY_CSC1,
    SCE_GXM_TEXTURE_FORMAT_VYUY422_CSC1 = SCE_GXM_TEXTURE_BASE_FORMAT_YUV422 | SCE_GXM_TEXTURE_SWIZZLE_VYUY_CSC1,

    SCE_GXM_TEXTURE_FORMAT_P4_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_P4 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_P4_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_P4 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_P4_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_P4 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_P4_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_P4 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_P4_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_P4 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_P4_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_P4 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_P4_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_P4 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_P4_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_P4 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_P8_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_P8 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_P8_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_P8 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_P8_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_P8 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_P8_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_P8 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_P8_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_P8 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_P8_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_P8 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_P8_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_P8 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_P8_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_P8 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    SCE_GXM_TEXTURE_FORMAT_U8U8U8_BGR = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE3_BGR,
    SCE_GXM_TEXTURE_FORMAT_U8U8U8_RGB = SCE_GXM_TEXTURE_BASE_FORMAT_U8U8U8 | SCE_GXM_TEXTURE_SWIZZLE3_RGB,

    SCE_GXM_TEXTURE_FORMAT_S8S8S8_BGR = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE3_BGR,
    SCE_GXM_TEXTURE_FORMAT_S8S8S8_RGB = SCE_GXM_TEXTURE_BASE_FORMAT_S8S8S8 | SCE_GXM_TEXTURE_SWIZZLE3_RGB,

    SCE_GXM_TEXTURE_FORMAT_U2F10F10F10_ABGR = SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 | SCE_GXM_TEXTURE_SWIZZLE4_ABGR,
    SCE_GXM_TEXTURE_FORMAT_U2F10F10F10_ARGB = SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 | SCE_GXM_TEXTURE_SWIZZLE4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_F10F10F10U2_RGBA = SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 | SCE_GXM_TEXTURE_SWIZZLE4_RGBA,
    SCE_GXM_TEXTURE_FORMAT_F10F10F10U2_BGRA = SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 | SCE_GXM_TEXTURE_SWIZZLE4_BGRA,
    SCE_GXM_TEXTURE_FORMAT_X2F10F10F10_1BGR = SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 | SCE_GXM_TEXTURE_SWIZZLE4_1BGR,
    SCE_GXM_TEXTURE_FORMAT_X2F10F10F10_1RGB = SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 | SCE_GXM_TEXTURE_SWIZZLE4_1RGB,
    SCE_GXM_TEXTURE_FORMAT_F10F10F10X2_RGB1 = SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 | SCE_GXM_TEXTURE_SWIZZLE4_RGB1,
    SCE_GXM_TEXTURE_FORMAT_F10F10F10X2_BGR1 = SCE_GXM_TEXTURE_BASE_FORMAT_U2F10F10F10 | SCE_GXM_TEXTURE_SWIZZLE4_BGR1,

    // Legacy formats

    SCE_GXM_TEXTURE_FORMAT_L8 = SCE_GXM_TEXTURE_FORMAT_U8_1RRR,
    SCE_GXM_TEXTURE_FORMAT_A8 = SCE_GXM_TEXTURE_FORMAT_U8_R000,
    SCE_GXM_TEXTURE_FORMAT_R8 = SCE_GXM_TEXTURE_FORMAT_U8_000R,
    SCE_GXM_TEXTURE_FORMAT_A4R4G4B4 = SCE_GXM_TEXTURE_FORMAT_U4U4U4U4_ARGB,
    SCE_GXM_TEXTURE_FORMAT_A1R5G5B5 = SCE_GXM_TEXTURE_FORMAT_U1U5U5U5_ARGB,
    SCE_GXM_TEXTURE_FORMAT_R5G6B5 = SCE_GXM_TEXTURE_FORMAT_U5U6U5_RGB,
    SCE_GXM_TEXTURE_FORMAT_A8L8 = SCE_GXM_TEXTURE_FORMAT_U8U8_GRRR,
    SCE_GXM_TEXTURE_FORMAT_L8A8 = SCE_GXM_TEXTURE_FORMAT_U8U8_RGGG,
    SCE_GXM_TEXTURE_FORMAT_G8R8 = SCE_GXM_TEXTURE_FORMAT_U8U8_00GR,
    SCE_GXM_TEXTURE_FORMAT_L16 = SCE_GXM_TEXTURE_FORMAT_U16_1RRR,
    SCE_GXM_TEXTURE_FORMAT_A16 = SCE_GXM_TEXTURE_FORMAT_U16_R000,
    SCE_GXM_TEXTURE_FORMAT_R16 = SCE_GXM_TEXTURE_FORMAT_U16_000R,
    SCE_GXM_TEXTURE_FORMAT_D16 = SCE_GXM_TEXTURE_FORMAT_U16_R,
    SCE_GXM_TEXTURE_FORMAT_LF16 = SCE_GXM_TEXTURE_FORMAT_F16_1RRR,
    SCE_GXM_TEXTURE_FORMAT_AF16 = SCE_GXM_TEXTURE_FORMAT_F16_R000,
    SCE_GXM_TEXTURE_FORMAT_RF16 = SCE_GXM_TEXTURE_FORMAT_F16_000R,
    SCE_GXM_TEXTURE_FORMAT_A8R8G8B8 = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB,
    SCE_GXM_TEXTURE_FORMAT_A8B8G8R8 = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR,
    SCE_GXM_TEXTURE_FORMAT_AF16LF16 = SCE_GXM_TEXTURE_FORMAT_F16F16_GRRR,
    SCE_GXM_TEXTURE_FORMAT_LF16AF16 = SCE_GXM_TEXTURE_FORMAT_F16F16_RGGG,
    SCE_GXM_TEXTURE_FORMAT_GF16RF16 = SCE_GXM_TEXTURE_FORMAT_F16F16_00GR,
    SCE_GXM_TEXTURE_FORMAT_LF32M = SCE_GXM_TEXTURE_FORMAT_F32M_1RRR,
    SCE_GXM_TEXTURE_FORMAT_AF32M = SCE_GXM_TEXTURE_FORMAT_F32M_R000,
    SCE_GXM_TEXTURE_FORMAT_RF32M = SCE_GXM_TEXTURE_FORMAT_F32M_000R,
    SCE_GXM_TEXTURE_FORMAT_DF32M = SCE_GXM_TEXTURE_FORMAT_F32M_R,
    SCE_GXM_TEXTURE_FORMAT_VYUY = SCE_GXM_TEXTURE_FORMAT_VYUY422_CSC0,
    SCE_GXM_TEXTURE_FORMAT_YVYU = SCE_GXM_TEXTURE_FORMAT_YVYU422_CSC0,
    SCE_GXM_TEXTURE_FORMAT_UBC1 = SCE_GXM_TEXTURE_FORMAT_UBC1_ABGR,
    SCE_GXM_TEXTURE_FORMAT_UBC2 = SCE_GXM_TEXTURE_FORMAT_UBC2_ABGR,
    SCE_GXM_TEXTURE_FORMAT_UBC3 = SCE_GXM_TEXTURE_FORMAT_UBC3_ABGR,
    SCE_GXM_TEXTURE_FORMAT_PVRT2BPP = SCE_GXM_TEXTURE_FORMAT_PVRT2BPP_ABGR,
    SCE_GXM_TEXTURE_FORMAT_PVRT4BPP = SCE_GXM_TEXTURE_FORMAT_PVRT4BPP_ABGR,
    SCE_GXM_TEXTURE_FORMAT_PVRTII2BPP = SCE_GXM_TEXTURE_FORMAT_PVRTII2BPP_ABGR,
    SCE_GXM_TEXTURE_FORMAT_PVRTII4BPP = SCE_GXM_TEXTURE_FORMAT_PVRTII4BPP_ABGR
};

enum SceGxmColorSwizzle4Mode : uint32_t {
    SCE_GXM_COLOR_SWIZZLE4_ABGR = 0x00000000u,
    SCE_GXM_COLOR_SWIZZLE4_ARGB = 0x00100000u,
    SCE_GXM_COLOR_SWIZZLE4_RGBA = 0x00200000u,
    SCE_GXM_COLOR_SWIZZLE4_BGRA = 0x00300000u
};

enum SceGxmColorSwizzle3Mode : uint32_t {
    SCE_GXM_COLOR_SWIZZLE3_BGR = 0x00000000u,
    SCE_GXM_COLOR_SWIZZLE3_RGB = 0x00100000u
};

enum SceGxmColorSwizzle2Mode : uint32_t {
    SCE_GXM_COLOR_SWIZZLE2_GR = 0x00000000u,
    SCE_GXM_COLOR_SWIZZLE2_RG = 0x00100000u,
    SCE_GXM_COLOR_SWIZZLE2_RA = 0x00200000u,
    SCE_GXM_COLOR_SWIZZLE2_AR = 0x00300000u
};

enum SceGxmColorSwizzle1Mode : uint32_t {
    SCE_GXM_COLOR_SWIZZLE1_R = 0x00000000u,
    SCE_GXM_COLOR_SWIZZLE1_G = 0x00100000u,
    SCE_GXM_COLOR_SWIZZLE1_A = 0x00100000u
};

enum SceGxmColorBaseFormat : uint32_t {
    SCE_GXM_COLOR_BASE_FORMAT_U8U8U8U8 = 0x00000000,
    SCE_GXM_COLOR_BASE_FORMAT_U8U8U8 = 0x10000000,
    SCE_GXM_COLOR_BASE_FORMAT_U5U6U5 = 0x30000000,
    SCE_GXM_COLOR_BASE_FORMAT_U1U5U5U5 = 0x40000000,
    SCE_GXM_COLOR_BASE_FORMAT_U4U4U4U4 = 0x50000000,
    SCE_GXM_COLOR_BASE_FORMAT_U8U3U3U2 = 0x60000000,
    SCE_GXM_COLOR_BASE_FORMAT_F16 = 0xF0000000,
    SCE_GXM_COLOR_BASE_FORMAT_F16F16 = 0x00800000,
    SCE_GXM_COLOR_BASE_FORMAT_F32 = 0x10800000,
    SCE_GXM_COLOR_BASE_FORMAT_S16 = 0x20800000,
    SCE_GXM_COLOR_BASE_FORMAT_S16S16 = 0x30800000,
    SCE_GXM_COLOR_BASE_FORMAT_U16 = 0x40800000,
    SCE_GXM_COLOR_BASE_FORMAT_U16U16 = 0x50800000,
    SCE_GXM_COLOR_BASE_FORMAT_U2U10U10U10 = 0x60800000,
    SCE_GXM_COLOR_BASE_FORMAT_U8 = 0x80800000,
    SCE_GXM_COLOR_BASE_FORMAT_S8 = 0x90800000,
    SCE_GXM_COLOR_BASE_FORMAT_S5S5U6 = 0xA0800000,
    SCE_GXM_COLOR_BASE_FORMAT_U8U8 = 0xB0800000,
    SCE_GXM_COLOR_BASE_FORMAT_S8S8 = 0xC0800000,
    SCE_GXM_COLOR_BASE_FORMAT_U8S8S8U8 = 0xD0800000,
    SCE_GXM_COLOR_BASE_FORMAT_S8S8S8S8 = 0xE0800000,
    SCE_GXM_COLOR_BASE_FORMAT_F16F16F16F16 = 0x01000000,
    SCE_GXM_COLOR_BASE_FORMAT_F32F32 = 0x11000000,
    SCE_GXM_COLOR_BASE_FORMAT_F11F11F10 = 0x21000000,
    SCE_GXM_COLOR_BASE_FORMAT_SE5M9M9M9 = 0x31000000,
    SCE_GXM_COLOR_BASE_FORMAT_U2F10F10F10 = 0x41000000
};

template <typename T>
constexpr static inline uint32_t operator|(const SceGxmColorBaseFormat a, const T b) {
    return static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
};

enum SceGxmColorFormat : uint32_t {

    SCE_GXM_COLOR_FORMAT_U8U8U8U8_ABGR = SCE_GXM_COLOR_BASE_FORMAT_U8U8U8U8 | SCE_GXM_COLOR_SWIZZLE4_ABGR,
    SCE_GXM_COLOR_FORMAT_U8U8U8U8_ARGB = SCE_GXM_COLOR_BASE_FORMAT_U8U8U8U8 | SCE_GXM_COLOR_SWIZZLE4_ARGB,
    SCE_GXM_COLOR_FORMAT_U8U8U8U8_RGBA = SCE_GXM_COLOR_BASE_FORMAT_U8U8U8U8 | SCE_GXM_COLOR_SWIZZLE4_RGBA,
    SCE_GXM_COLOR_FORMAT_U8U8U8U8_BGRA = SCE_GXM_COLOR_BASE_FORMAT_U8U8U8U8 | SCE_GXM_COLOR_SWIZZLE4_BGRA,

    SCE_GXM_COLOR_FORMAT_U8U8U8_BGR = SCE_GXM_COLOR_BASE_FORMAT_U8U8U8 | SCE_GXM_COLOR_SWIZZLE3_BGR,
    SCE_GXM_COLOR_FORMAT_U8U8U8_RGB = SCE_GXM_COLOR_BASE_FORMAT_U8U8U8 | SCE_GXM_COLOR_SWIZZLE3_RGB,

    SCE_GXM_COLOR_FORMAT_U5U6U5_BGR = SCE_GXM_COLOR_BASE_FORMAT_U5U6U5 | SCE_GXM_COLOR_SWIZZLE3_BGR,
    SCE_GXM_COLOR_FORMAT_U5U6U5_RGB = SCE_GXM_COLOR_BASE_FORMAT_U5U6U5 | SCE_GXM_COLOR_SWIZZLE3_RGB,

    SCE_GXM_COLOR_FORMAT_U1U5U5U5_ABGR = SCE_GXM_COLOR_BASE_FORMAT_U1U5U5U5 | SCE_GXM_COLOR_SWIZZLE4_ABGR,
    SCE_GXM_COLOR_FORMAT_U1U5U5U5_ARGB = SCE_GXM_COLOR_BASE_FORMAT_U1U5U5U5 | SCE_GXM_COLOR_SWIZZLE4_ARGB,
    SCE_GXM_COLOR_FORMAT_U5U5U5U1_RGBA = SCE_GXM_COLOR_BASE_FORMAT_U1U5U5U5 | SCE_GXM_COLOR_SWIZZLE4_RGBA,
    SCE_GXM_COLOR_FORMAT_U5U5U5U1_BGRA = SCE_GXM_COLOR_BASE_FORMAT_U1U5U5U5 | SCE_GXM_COLOR_SWIZZLE4_BGRA,

    SCE_GXM_COLOR_FORMAT_U4U4U4U4_ABGR = SCE_GXM_COLOR_BASE_FORMAT_U4U4U4U4 | SCE_GXM_COLOR_SWIZZLE4_ABGR,
    SCE_GXM_COLOR_FORMAT_U4U4U4U4_ARGB = SCE_GXM_COLOR_BASE_FORMAT_U4U4U4U4 | SCE_GXM_COLOR_SWIZZLE4_ARGB,
    SCE_GXM_COLOR_FORMAT_U4U4U4U4_RGBA = SCE_GXM_COLOR_BASE_FORMAT_U4U4U4U4 | SCE_GXM_COLOR_SWIZZLE4_RGBA,
    SCE_GXM_COLOR_FORMAT_U4U4U4U4_BGRA = SCE_GXM_COLOR_BASE_FORMAT_U4U4U4U4 | SCE_GXM_COLOR_SWIZZLE4_BGRA,

    SCE_GXM_COLOR_FORMAT_U8U3U3U2_ARGB = SCE_GXM_COLOR_BASE_FORMAT_U8U3U3U2,

    SCE_GXM_COLOR_FORMAT_F16_R = SCE_GXM_COLOR_BASE_FORMAT_F16 | SCE_GXM_COLOR_SWIZZLE1_R,
    SCE_GXM_COLOR_FORMAT_F16_G = SCE_GXM_COLOR_BASE_FORMAT_F16 | SCE_GXM_COLOR_SWIZZLE1_G,

    SCE_GXM_COLOR_FORMAT_F16F16_GR = SCE_GXM_COLOR_BASE_FORMAT_F16F16 | SCE_GXM_COLOR_SWIZZLE2_GR,
    SCE_GXM_COLOR_FORMAT_F16F16_RG = SCE_GXM_COLOR_BASE_FORMAT_F16F16 | SCE_GXM_COLOR_SWIZZLE2_RG,

    SCE_GXM_COLOR_FORMAT_F32_R = SCE_GXM_COLOR_BASE_FORMAT_F32 | SCE_GXM_COLOR_SWIZZLE1_R,

    SCE_GXM_COLOR_FORMAT_S16_R = SCE_GXM_COLOR_BASE_FORMAT_S16 | SCE_GXM_COLOR_SWIZZLE1_R,
    SCE_GXM_COLOR_FORMAT_S16_G = SCE_GXM_COLOR_BASE_FORMAT_S16 | SCE_GXM_COLOR_SWIZZLE1_G,

    SCE_GXM_COLOR_FORMAT_S16S16_GR = SCE_GXM_COLOR_BASE_FORMAT_S16S16 | SCE_GXM_COLOR_SWIZZLE2_GR,
    SCE_GXM_COLOR_FORMAT_S16S16_RG = SCE_GXM_COLOR_BASE_FORMAT_S16S16 | SCE_GXM_COLOR_SWIZZLE2_RG,

    SCE_GXM_COLOR_FORMAT_U16_R = SCE_GXM_COLOR_BASE_FORMAT_U16 | SCE_GXM_COLOR_SWIZZLE1_R,
    SCE_GXM_COLOR_FORMAT_U16_G = SCE_GXM_COLOR_BASE_FORMAT_U16 | SCE_GXM_COLOR_SWIZZLE1_G,

    SCE_GXM_COLOR_FORMAT_U16U16_GR = SCE_GXM_COLOR_BASE_FORMAT_U16U16 | SCE_GXM_COLOR_SWIZZLE2_GR,
    SCE_GXM_COLOR_FORMAT_U16U16_RG = SCE_GXM_COLOR_BASE_FORMAT_U16U16 | SCE_GXM_COLOR_SWIZZLE2_RG,

    SCE_GXM_COLOR_FORMAT_U2U10U10U10_ABGR = SCE_GXM_COLOR_BASE_FORMAT_U2U10U10U10 | SCE_GXM_COLOR_SWIZZLE4_ABGR,
    SCE_GXM_COLOR_FORMAT_U2U10U10U10_ARGB = SCE_GXM_COLOR_BASE_FORMAT_U2U10U10U10 | SCE_GXM_COLOR_SWIZZLE4_ARGB,
    SCE_GXM_COLOR_FORMAT_U10U10U10U2_RGBA = SCE_GXM_COLOR_BASE_FORMAT_U2U10U10U10 | SCE_GXM_COLOR_SWIZZLE4_RGBA,
    SCE_GXM_COLOR_FORMAT_U10U10U10U2_BGRA = SCE_GXM_COLOR_BASE_FORMAT_U2U10U10U10 | SCE_GXM_COLOR_SWIZZLE4_BGRA,

    SCE_GXM_COLOR_FORMAT_U8_R = SCE_GXM_COLOR_BASE_FORMAT_U8 | SCE_GXM_COLOR_SWIZZLE1_R,
    SCE_GXM_COLOR_FORMAT_U8_A = SCE_GXM_COLOR_BASE_FORMAT_U8 | SCE_GXM_COLOR_SWIZZLE1_A,

    SCE_GXM_COLOR_FORMAT_S8_R = SCE_GXM_COLOR_BASE_FORMAT_S8 | SCE_GXM_COLOR_SWIZZLE1_R,
    SCE_GXM_COLOR_FORMAT_S8_A = SCE_GXM_COLOR_BASE_FORMAT_S8 | SCE_GXM_COLOR_SWIZZLE1_A,

    SCE_GXM_COLOR_FORMAT_U6S5S5_BGR = SCE_GXM_COLOR_BASE_FORMAT_S5S5U6 | SCE_GXM_COLOR_SWIZZLE3_BGR,
    SCE_GXM_COLOR_FORMAT_S5S5U6_RGB = SCE_GXM_COLOR_BASE_FORMAT_S5S5U6 | SCE_GXM_COLOR_SWIZZLE3_RGB,

    SCE_GXM_COLOR_FORMAT_U8U8_GR = SCE_GXM_COLOR_BASE_FORMAT_U8U8 | SCE_GXM_COLOR_SWIZZLE2_GR,
    SCE_GXM_COLOR_FORMAT_U8U8_RG = SCE_GXM_COLOR_BASE_FORMAT_U8U8 | SCE_GXM_COLOR_SWIZZLE2_RG,
    SCE_GXM_COLOR_FORMAT_U8U8_RA = SCE_GXM_COLOR_BASE_FORMAT_U8U8 | SCE_GXM_COLOR_SWIZZLE2_RA,
    SCE_GXM_COLOR_FORMAT_U8U8_AR = SCE_GXM_COLOR_BASE_FORMAT_U8U8 | SCE_GXM_COLOR_SWIZZLE2_AR,

    SCE_GXM_COLOR_FORMAT_S8S8_GR = SCE_GXM_COLOR_BASE_FORMAT_S8S8 | SCE_GXM_COLOR_SWIZZLE2_GR,
    SCE_GXM_COLOR_FORMAT_S8S8_RG = SCE_GXM_COLOR_BASE_FORMAT_S8S8 | SCE_GXM_COLOR_SWIZZLE2_RG,
    SCE_GXM_COLOR_FORMAT_S8S8_RA = SCE_GXM_COLOR_BASE_FORMAT_S8S8 | SCE_GXM_COLOR_SWIZZLE2_RA,
    SCE_GXM_COLOR_FORMAT_S8S8_AR = SCE_GXM_COLOR_BASE_FORMAT_S8S8 | SCE_GXM_COLOR_SWIZZLE2_AR,

    SCE_GXM_COLOR_FORMAT_U8S8S8U8_ABGR = SCE_GXM_COLOR_BASE_FORMAT_U8S8S8U8 | SCE_GXM_COLOR_SWIZZLE4_ABGR,
    SCE_GXM_COLOR_FORMAT_U8U8S8S8_ARGB = SCE_GXM_COLOR_BASE_FORMAT_U8S8S8U8 | SCE_GXM_COLOR_SWIZZLE4_ARGB,
    SCE_GXM_COLOR_FORMAT_U8S8S8U8_RGBA = SCE_GXM_COLOR_BASE_FORMAT_U8S8S8U8 | SCE_GXM_COLOR_SWIZZLE4_RGBA,
    SCE_GXM_COLOR_FORMAT_S8S8U8U8_BGRA = SCE_GXM_COLOR_BASE_FORMAT_U8S8S8U8 | SCE_GXM_COLOR_SWIZZLE4_BGRA,

    SCE_GXM_COLOR_FORMAT_S8S8S8S8_ABGR = SCE_GXM_COLOR_BASE_FORMAT_S8S8S8S8 | SCE_GXM_COLOR_SWIZZLE4_ABGR,
    SCE_GXM_COLOR_FORMAT_S8S8S8S8_ARGB = SCE_GXM_COLOR_BASE_FORMAT_S8S8S8S8 | SCE_GXM_COLOR_SWIZZLE4_ARGB,
    SCE_GXM_COLOR_FORMAT_S8S8S8S8_RGBA = SCE_GXM_COLOR_BASE_FORMAT_S8S8S8S8 | SCE_GXM_COLOR_SWIZZLE4_RGBA,
    SCE_GXM_COLOR_FORMAT_S8S8S8S8_BGRA = SCE_GXM_COLOR_BASE_FORMAT_S8S8S8S8 | SCE_GXM_COLOR_SWIZZLE4_BGRA,

    SCE_GXM_COLOR_FORMAT_F16F16F16F16_ABGR = SCE_GXM_COLOR_BASE_FORMAT_F16F16F16F16 | SCE_GXM_COLOR_SWIZZLE4_ABGR,
    SCE_GXM_COLOR_FORMAT_F16F16F16F16_ARGB = SCE_GXM_COLOR_BASE_FORMAT_F16F16F16F16 | SCE_GXM_COLOR_SWIZZLE4_ARGB,
    SCE_GXM_COLOR_FORMAT_F16F16F16F16_RGBA = SCE_GXM_COLOR_BASE_FORMAT_F16F16F16F16 | SCE_GXM_COLOR_SWIZZLE4_RGBA,
    SCE_GXM_COLOR_FORMAT_F16F16F16F16_BGRA = SCE_GXM_COLOR_BASE_FORMAT_F16F16F16F16 | SCE_GXM_COLOR_SWIZZLE4_BGRA,

    SCE_GXM_COLOR_FORMAT_F32F32_GR = SCE_GXM_COLOR_BASE_FORMAT_F32F32 | SCE_GXM_COLOR_SWIZZLE2_GR,
    SCE_GXM_COLOR_FORMAT_F32F32_RG = SCE_GXM_COLOR_BASE_FORMAT_F32F32 | SCE_GXM_COLOR_SWIZZLE2_RG,

    SCE_GXM_COLOR_FORMAT_F10F11F11_BGR = SCE_GXM_COLOR_BASE_FORMAT_F11F11F10 | SCE_GXM_COLOR_SWIZZLE3_BGR,
    SCE_GXM_COLOR_FORMAT_F11F11F10_RGB = SCE_GXM_COLOR_BASE_FORMAT_F11F11F10 | SCE_GXM_COLOR_SWIZZLE3_RGB,

    SCE_GXM_COLOR_FORMAT_SE5M9M9M9_BGR = SCE_GXM_COLOR_BASE_FORMAT_SE5M9M9M9 | SCE_GXM_COLOR_SWIZZLE3_BGR,
    SCE_GXM_COLOR_FORMAT_SE5M9M9M9_RGB = SCE_GXM_COLOR_BASE_FORMAT_SE5M9M9M9 | SCE_GXM_COLOR_SWIZZLE3_RGB,

    SCE_GXM_COLOR_FORMAT_U2F10F10F10_ABGR = SCE_GXM_COLOR_BASE_FORMAT_U2F10F10F10 | SCE_GXM_COLOR_SWIZZLE4_ABGR,
    SCE_GXM_COLOR_FORMAT_U2F10F10F10_ARGB = SCE_GXM_COLOR_BASE_FORMAT_U2F10F10F10 | SCE_GXM_COLOR_SWIZZLE4_ARGB,
    SCE_GXM_COLOR_FORMAT_F10F10F10U2_RGBA = SCE_GXM_COLOR_BASE_FORMAT_U2F10F10F10 | SCE_GXM_COLOR_SWIZZLE4_RGBA,
    SCE_GXM_COLOR_FORMAT_F10F10F10U2_BGRA = SCE_GXM_COLOR_BASE_FORMAT_U2F10F10F10 | SCE_GXM_COLOR_SWIZZLE4_BGRA,

    // Legacy formats

    SCE_GXM_COLOR_FORMAT_A8B8G8R8 = SCE_GXM_COLOR_FORMAT_U8U8U8U8_ABGR,
    SCE_GXM_COLOR_FORMAT_A8R8G8B8 = SCE_GXM_COLOR_FORMAT_U8U8U8U8_ARGB,
    SCE_GXM_COLOR_FORMAT_R5G6B5 = SCE_GXM_COLOR_FORMAT_U5U6U5_RGB,
    SCE_GXM_COLOR_FORMAT_A1R5G5B5 = SCE_GXM_COLOR_FORMAT_U1U5U5U5_ARGB,
    SCE_GXM_COLOR_FORMAT_A4R4G4B4 = SCE_GXM_COLOR_FORMAT_U4U4U4U4_ARGB,
    SCE_GXM_COLOR_FORMAT_A8 = SCE_GXM_COLOR_FORMAT_U8_A
};

enum SceGxmColorSurfaceType : uint32_t {
    SCE_GXM_COLOR_SURFACE_LINEAR = 0x00000000u,
    SCE_GXM_COLOR_SURFACE_TILED = 0x04000000u,
    SCE_GXM_COLOR_SURFACE_SWIZZLED = 0x08000000u
};

enum SceGxmColorSurfaceGammaMode : uint32_t {
    SCE_GXM_COLOR_SURFACE_GAMMA_NONE = 0x00000000u,
    SCE_GXM_COLOR_SURFACE_GAMMA_R = 0x00001000u,
    SCE_GXM_COLOR_SURFACE_GAMMA_GR = 0x00003000u,
    SCE_GXM_COLOR_SURFACE_GAMMA_BGR = 0x00001000u
};

enum SceGxmColorSurfaceScaleMode : uint32_t {
    SCE_GXM_COLOR_SURFACE_SCALE_NONE = 0x00000000u,
    SCE_GXM_COLOR_SURFACE_SCALE_MSAA_DOWNSCALE = 0x00000001u
};

enum SceGxmMidSceneFlags : uint32_t {
    SCE_GXM_MIDSCENE_PRESERVE_DEFAULT_UNIFORM_BUFFERS = 0x00000001U
};

enum SceGxmOutputRegisterSize : uint32_t {
    SCE_GXM_OUTPUT_REGISTER_SIZE_32BIT = 0x00000000u,
    SCE_GXM_OUTPUT_REGISTER_SIZE_64BIT = 0x00000001u
};

enum SceGxmVisibilityTestMode : uint32_t {
    SCE_GXM_VISIBILITY_TEST_DISABLED = 0x00000000u,
    SCE_GXM_VISIBILITY_TEST_ENABLED = 0x00004000u
};

enum SceGxmVisibilityTestOp : uint32_t {
    SCE_GXM_VISIBILITY_TEST_OP_INCREMENT = 0x00000000u,
    SCE_GXM_VISIBILITY_TEST_OP_SET = 0x00040000u
};

enum SceGxmOutputRegisterFormat {
    SCE_GXM_OUTPUT_REGISTER_FORMAT_DECLARED,
    SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
    SCE_GXM_OUTPUT_REGISTER_FORMAT_CHAR4,
    SCE_GXM_OUTPUT_REGISTER_FORMAT_USHORT2,
    SCE_GXM_OUTPUT_REGISTER_FORMAT_SHORT2,
    SCE_GXM_OUTPUT_REGISTER_FORMAT_HALF4,
    SCE_GXM_OUTPUT_REGISTER_FORMAT_HALF2,
    SCE_GXM_OUTPUT_REGISTER_FORMAT_FLOAT2,
    SCE_GXM_OUTPUT_REGISTER_FORMAT_FLOAT
};

enum SceGxmTextureGammaMode : uint32_t {
    SCE_GXM_TEXTURE_GAMMA_NONE = 0x00000000u,
    SCE_GXM_TEXTURE_GAMMA_R = 0x08000000u,
    SCE_GXM_TEXTURE_GAMMA_GR = 0x18000000u,
    SCE_GXM_TEXTURE_GAMMA_BGR = 0x08000000u
};

enum SceGxmTextureNormalizeMode : uint32_t {
    SCE_GXM_TEXTURE_NORMALIZE_DISABLED = 0x00000000u,
    SCE_GXM_TEXTURE_NORMALIZE_ENABLED = 0x80000000u
};

enum SceGxmTransferColorKeyMode {
    SCE_GXM_TRANSFER_COLORKEY_NONE,
    SCE_GXM_TRANSFER_COLORKEY_PASS,
    SCE_GXM_TRANSFER_COLORKEY_REJECT
};

enum SceGxmTransferFlags : uint32_t {
    SCE_GXM_TRANSFER_FRAGMENT_SYNC = 0x00000001U,
    SCE_GXM_TRANSFER_VERTEX_SYNC = 0x00000002U
};

enum SceGxmTransferFormat : uint32_t {
    SCE_GXM_TRANSFER_FORMAT_U8_R = 0x00000000U,
    SCE_GXM_TRANSFER_FORMAT_U4U4U4U4_ABGR = 0x00010000U,
    SCE_GXM_TRANSFER_FORMAT_U1U5U5U5_ABGR = 0x00020000U,
    SCE_GXM_TRANSFER_FORMAT_U5U6U5_BGR = 0x00030000U,
    SCE_GXM_TRANSFER_FORMAT_U8U8_GR = 0x00040000U,
    SCE_GXM_TRANSFER_FORMAT_U8U8U8_BGR = 0x00050000U,
    SCE_GXM_TRANSFER_FORMAT_U8U8U8U8_ABGR = 0x00060000U,
    SCE_GXM_TRANSFER_FORMAT_VYUY422 = 0x00070000U,
    SCE_GXM_TRANSFER_FORMAT_YVYU422 = 0x00080000U,
    SCE_GXM_TRANSFER_FORMAT_UYVY422 = 0x00090000U,
    SCE_GXM_TRANSFER_FORMAT_YUYV422 = 0x000a0000U,
    SCE_GXM_TRANSFER_FORMAT_U2U10U10U10_ABGR = 0x000d0000U,
    SCE_GXM_TRANSFER_FORMAT_RAW16 = 0x000f0000U,
    SCE_GXM_TRANSFER_FORMAT_RAW32 = 0x00110000U,
    SCE_GXM_TRANSFER_FORMAT_RAW64 = 0x00120000U,
    SCE_GXM_TRANSFER_FORMAT_RAW128 = 0x00130000U
};

enum SceGxmTransferType : uint32_t {
    SCE_GXM_TRANSFER_LINEAR = 0x00000000U,
    SCE_GXM_TRANSFER_TILED = 0x00400000U,
    SCE_GXM_TRANSFER_SWIZZLED = 0x00800000U
};

enum SceGxmDepthStencilForceLoadMode : uint32_t {
    SCE_GXM_DEPTH_STENCIL_FORCE_LOAD_DISABLED = 0x00000000u,
    SCE_GXM_DEPTH_STENCIL_FORCE_LOAD_ENABLED = 0x00000002u
};

template <typename T>
constexpr static inline uint32_t operator|(const SceGxmDepthStencilForceLoadMode a, const T b) {
    return static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
};

enum SceGxmDepthStencilForceStoreMode : uint32_t {
    SCE_GXM_DEPTH_STENCIL_FORCE_STORE_DISABLED = 0x00000000u,
    SCE_GXM_DEPTH_STENCIL_FORCE_STORE_ENABLED = 0x00000004u
};

template <typename T>
constexpr static inline uint32_t operator|(const SceGxmDepthStencilForceStoreMode a, const T b) {
    return static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
};

enum SceGxmColorSurfaceDitherMode : uint32_t {
    SCE_GXM_COLOR_SURFACE_DITHER_DISABLED = 0x00000000u,
    SCE_GXM_COLOR_SURFACE_DITHER_ENABLED = 0x00000008u
};

enum SceGxmDepthStencilSurfaceType : uint32_t {
    SCE_GXM_DEPTH_STENCIL_SURFACE_LINEAR = 0x00000000u,
    SCE_GXM_DEPTH_STENCIL_SURFACE_TILED = 0x00011000u
};

enum SceGxmMemoryAttribFlags {
    SCE_GXM_MEMORY_ATTRIB_READ = 1,
    SCE_GXM_MEMORY_ATTRIB_WRITE = 2,
    SCE_GXM_MEMORY_ATTRIB_RW = (SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE)
};

enum SceGxmAttributeFormat : uint8_t {
    SCE_GXM_ATTRIBUTE_FORMAT_U8,
    SCE_GXM_ATTRIBUTE_FORMAT_S8,
    SCE_GXM_ATTRIBUTE_FORMAT_U16,
    SCE_GXM_ATTRIBUTE_FORMAT_S16,
    SCE_GXM_ATTRIBUTE_FORMAT_U8N,
    SCE_GXM_ATTRIBUTE_FORMAT_S8N,
    SCE_GXM_ATTRIBUTE_FORMAT_U16N,
    SCE_GXM_ATTRIBUTE_FORMAT_S16N,
    SCE_GXM_ATTRIBUTE_FORMAT_F16,
    SCE_GXM_ATTRIBUTE_FORMAT_F32,
    SCE_GXM_ATTRIBUTE_FORMAT_UNTYPED
};

enum SceGxmErrorCode : uint32_t {
    SCE_GXM_ERROR_UNINITIALIZED = 0x805B0000,
    SCE_GXM_ERROR_ALREADY_INITIALIZED = 0x805B0001,
    SCE_GXM_ERROR_OUT_OF_MEMORY = 0x805B0002,
    SCE_GXM_ERROR_INVALID_VALUE = 0x805B0003,
    SCE_GXM_ERROR_INVALID_POINTER = 0x805B0004,
    SCE_GXM_ERROR_INVALID_ALIGNMENT = 0x805B0005,
    SCE_GXM_ERROR_NOT_WITHIN_SCENE = 0x805B0006,
    SCE_GXM_ERROR_WITHIN_SCENE = 0x805B0007,
    SCE_GXM_ERROR_NULL_PROGRAM = 0x805B0008,
    SCE_GXM_ERROR_UNSUPPORTED = 0x805B0009,
    SCE_GXM_ERROR_PATCHER_INTERNAL = 0x805B000A,
    SCE_GXM_ERROR_RESERVE_FAILED = 0x805B000B,
    SCE_GXM_ERROR_PROGRAM_IN_USE = 0x805B000C,
    SCE_GXM_ERROR_INVALID_INDEX_COUNT = 0x805B000D,
    SCE_GXM_ERROR_INVALID_POLYGON_MODE = 0x805B000E,
    SCE_GXM_ERROR_INVALID_SAMPLER_RESULT_TYPE_PRECISION = 0x805B000F,
    SCE_GXM_ERROR_INVALID_SAMPLER_RESULT_TYPE_COMPONENT_COUNT = 0x805B0010,
    SCE_GXM_ERROR_UNIFORM_BUFFER_NOT_RESERVED = 0x805B0011,
    SCE_GXM_ERROR_INVALID_AUXILIARY_SURFACE = 0x805B0013,
    SCE_GXM_ERROR_INVALID_PRECOMPUTED_DRAW = 0x805B0014,
    SCE_GXM_ERROR_INVALID_PRECOMPUTED_VERTEX_STATE = 0x805B0015,
    SCE_GXM_ERROR_INVALID_PRECOMPUTED_FRAGMENT_STATE = 0x805B0016,
    SCE_GXM_ERROR_DRIVER = 0x805B0017,
    SCE_GXM_ERROR_INVALID_THREAD = 0x805B0018,
    SCE_GXM_ERROR_WITHIN_COMMAND_LIST = 0x805B002C,
    SCE_GXM_ERROR_NOT_WITHIN_COMMAND_LIST = 0x805B002D
};

enum SceGxmIndexSource {
    SCE_GXM_INDEX_SOURCE_EACH_VERTEX_16BIT = 0,
    SCE_GXM_INDEX_SOURCE_EACH_VERTEX_32BIT = 1,
    SCE_GXM_INDEX_SOURCE_EACH_INSTANCE_16BIT = 2,
    SCE_GXM_INDEX_SOURCE_EACH_INSTANCE_32BIT = 3
};

struct SceGxmVertexStream {
    uint16_t stride;
    uint16_t indexSource;
};

struct SceGxmProgram;
struct SceGxmVertexProgram;
struct SceGxmFragmentProgram;

struct SceGxmBlendInfo {
    SceGxmColorMask colorMask : 8;
    SceGxmBlendFunc colorFunc : 4;
    SceGxmBlendFunc alphaFunc : 4;
    SceGxmBlendFactor colorSrc : 4;
    SceGxmBlendFactor colorDst : 4;
    SceGxmBlendFactor alphaSrc : 4;
    SceGxmBlendFactor alphaDst : 4;
};

static_assert(sizeof(SceGxmBlendInfo) == 4, "Incorrect size.");

struct SceGxmTexture {
    // Control Word 0
    uint32_t unk0 : 3;
    uint32_t vaddr_mode : 3;
    uint32_t uaddr_mode : 3;
    uint32_t mip_filter : 1;
    uint32_t min_filter : 2;
    uint32_t mag_filter : 2;
    uint32_t unk1 : 3;
    uint32_t mip_count : 4;
    uint32_t lod_bias : 6;
    uint32_t gamma_mode : 2;
    uint32_t unk2 : 2;
    uint32_t format0 : 1;
    // Control Word 1
    union {
        struct {
            uint32_t height : 12;
            uint32_t width : 12;
        };

        struct {
            uint32_t height_base2 : 4;
            uint32_t unknown1 : 12;
            uint32_t width_base2 : 4;
            uint32_t unknown2 : 4;
        };

        struct {
            uint32_t whblock : 24;
            uint32_t base_format : 5;
            uint32_t type : 3;
        };
    };
    // Control Word 2
    uint32_t lod_min0 : 2;
    uint32_t data_addr : 30;
    // Control Word 3
    uint32_t palette_addr : 26;
    uint32_t lod_min1 : 2;
    uint32_t swizzle_format : 3;
    uint32_t normalize_mode : 1;

    SceGxmTextureType texture_type() const {
        return static_cast<SceGxmTextureType>(type << 29);
    }

    uint32_t true_mip_count() const {
        if (texture_type() == SCE_GXM_TEXTURE_LINEAR_STRIDED)
            return 1;

        uint32_t count = (mip_count + 1) & 15;
        return (count == 0) ? 1 : count; // 0 count is no mip chain, but there's still top level...
    }
};

static_assert(sizeof(SceGxmTexture) == 16);

struct SceGxmValidRegion {
    uint32_t xMax;
    uint32_t yMax;
};

typedef void *(*SceGxmDeferredContextCallback)(void *userData, uint32_t minSize, uint32_t *size);

// identical to ::SceGxmProgramType for now
// see SceGxmProgram.type field for details
enum SceGxmProgramType : uint8_t {
    Vertex = 0,
    Fragment = 1
};

enum SceGxmVertexProgramOutputs : int {
    _SCE_GXM_VERTEX_PROGRAM_OUTPUT_INVALID = 0,

    SCE_GXM_VERTEX_PROGRAM_OUTPUT_POSITION = 1 << 0,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_FOG = 1 << 1,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_COLOR0 = 1 << 2,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_COLOR1 = 1 << 3,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD0 = 1 << 4,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD1 = 1 << 5,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD2 = 1 << 6,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD3 = 1 << 7,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD4 = 1 << 8,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD5 = 1 << 9,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD6 = 1 << 10,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD7 = 1 << 11,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD8 = 1 << 12,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_TEXCOORD9 = 1 << 13,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_PSIZE = 1 << 14,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_CLIP0 = 1 << 15,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_CLIP1 = 1 << 16,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_CLIP2 = 1 << 17,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_CLIP3 = 1 << 18,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_CLIP4 = 1 << 19,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_CLIP5 = 1 << 20,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_CLIP6 = 1 << 21,
    SCE_GXM_VERTEX_PROGRAM_OUTPUT_CLIP7 = 1 << 22,

    _SCE_GXM_VERTEX_PROGRAM_OUTPUT_LAST = 1 << 23
};

#define OFFSET_FUNCTION(type, name, field)                                                        \
    const type *name() const {                                                                    \
        return reinterpret_cast<const type *>(reinterpret_cast<const uint8_t *>(&field) + field); \
    }
#define OFFSET_FUNCTION_CHECKED(type, name, field)                                                                  \
    const type *name() const {                                                                                      \
        return reinterpret_cast<const type *>(field ? reinterpret_cast<const uint8_t *>(&field) + field : nullptr); \
    }

#pragma pack(push, 1)
struct SceGxmProgramVertexVaryings {
    union {
        // Vertex Program variables
        struct {
            uint64_t attrib_pa_regs;
            uint64_t untyped_pa_regs;
        };

        // Fragment Program Variables
        struct {
            uint8_t unk0[8];
            uint8_t fragment_output_start; // this might be wrong
            uint8_t unk1;
            SceGxmParameterType output_param_type;
            uint8_t output_comp_count;

            uint16_t varyings_count;
            uint16_t pad0; // Might be the number of non-dependent samplers
        };
    };

    uint32_t vertex_outputs1; // includes everything except texcoord outputs
    uint32_t vertex_outputs2; // includes texcoord outputs
    uint32_t texcoord_pack_format; // 1 bit per texcoord. (0 - float, 1 - half)
    uint16_t semantic_index_offset;
    uint16_t semantic_instance_offset;
    OFFSET_FUNCTION_CHECKED(SceGxmProgramAttributeDescriptor, frag_attribute_descriptor, vertex_outputs1)
};
#pragma pack(pop)

static_assert(sizeof(SceGxmProgramVertexVaryings) == 32);

struct SceGxmProgramAttributeDescriptor {
    uint32_t attribute_info;
    uint32_t resource_index;
    uint32_t size;
    uint32_t component_info; ///< Total components and type
};

struct SceGxmDependentSampler {
    uint16_t resource_index_layout_offset; ///< The resource index of the sampler, in range of [index * 4, (index + 1) * 4)
    uint16_t sa_offset; ///< The SA offset correspond to the sampler
};

enum SceGxmFragmentProgramInputs : int {
    _SCE_GXM_FRAGMENT_PROGRAM_INPUT_NONE = 0,

    SCE_GXM_FRAGMENT_PROGRAM_INPUT_POSITION = 1 << 0,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_FOG = 1 << 1,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_COLOR0 = 1 << 2,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_COLOR1 = 1 << 3,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD0 = 1 << 4,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD1 = 1 << 5,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD2 = 1 << 6,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD3 = 1 << 7,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD4 = 1 << 8,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD5 = 1 << 9,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD6 = 1 << 10,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD7 = 1 << 11,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD8 = 1 << 12,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_TEXCOORD9 = 1 << 13,
    SCE_GXM_FRAGMENT_PROGRAM_INPUT_SPRITECOORD = 1 << 14,

    _SCE_GXM_FRAGMENT_PROGRAM_INPUT_LAST = 1 << 15
};

enum SceGxmProgramFlags : uint32_t {
    SCE_GXM_PROGRAM_FLAG_FRAGMENT = 1 << 0,
    SCE_GXM_PROGRAM_FLAG_PER_INSTANCE_MODE = 1 << 1,
    SCE_GXM_PROGRAM_FLAG_DISCARD_USED = 1 << 3,
    SCE_GXM_PROGRAM_FLAG_DEPTH_USED = 1 << 4,
    SCE_GXM_PROGRAM_FLAG_SPRITECOORD_USED = 1 << 5,
    SCE_GXM_PROGRAM_FLAG_NATIVECOLOR_USED = 1 << 6,
    SCE_GXM_PROGRAM_FLAG_FRAGCOLOR_USED = 1 << 7,
    SCE_GXM_PROGRAM_FLAG_NATIVECOLOR_MSAA2X = 1 << 8,
    SCE_GXM_PROGRAM_FLAG_NATIVECOLOR_MSAA4X = 1 << 9,
    // Note, I'm not sure about this one
    SCE_GXM_PROGRAM_FLAG_BUFFER_STORE = 1 << 14,
    SCE_GXM_PROGRAM_FLAG_OUTPUT_UNDEFINED = 1 << 16,
    SCE_GXM_PROGRAM_FLAG_INDEX_USED = 1 << 17,
    SCE_GXM_PROGRAM_FLAG_INSTANCE_USED = 1 << 18,
};

struct SceGxmUniformBufferInfo {
    uint16_t reside_buffer; ///< If reside buffer = 0, this is a in memory buffer. Likely SSBO
    uint16_t ldst_base_offset; ///< Point to the register number starting from container's base SA offset, storing base value.
    int32_t ldst_base_value; ///< Value representing the starting offset in bytes to load/store buffer data.
};

struct SceGxmProgramParameterContainer {
    uint16_t container_index;
    uint16_t unk02;
    uint16_t base_sa_offset;
    uint16_t size_in_f32;
};

struct SceGxmProgramLiteral {
    uint32_t offset;
    float data;
};

struct SceGxmProgram {
    uint32_t magic; // should be "GXP\0"

    uint8_t major_version; // min 1
    uint8_t minor_version; // min 4
    uint16_t sdk_version; // 0x350 - 3.50

    uint32_t size; // size of file - ignoring padding bytes at the end after SceGxmProgramParameter table

    uint32_t binary_guid;
    uint32_t source_guid;

    uint32_t program_flags;

    uint32_t buffer_flags; // Buffer flags. 2 bits per buffer. 0x1 - loaded into registers. 0x2 - read from memory

    uint32_t texunit_flags[2]; // Tex unit flags. 4 bits per tex unit. 0x1 is non dependent read, 0x2 is dependent.

    uint32_t parameter_count;
    uint32_t parameters_offset; // Number of bytes from the start of this field to the first parameter.
    uint32_t varyings_offset; // offset to vertex outputs / fragment inputs, relative to this field

    uint16_t primary_reg_count; // (PAs)
    uint16_t secondary_reg_count; // (SAs)
    uint32_t temp_reg_count1;
    uint16_t temp_reg_count2; // Temp reg count in selective rate(programmable blending) phase

    uint16_t primary_program_phase_count;
    uint32_t primary_program_instr_count;
    uint32_t primary_program_offset;

    uint32_t secondary_program_instr_count;
    uint32_t secondary_program_offset; // relative to the beginning of this field
    uint32_t secondary_program_offset_end; // relative to the beginning of this field

    uint32_t scratch_buffer_count;
    uint32_t thread_buffer_count;
    uint32_t literal_buffer_count;

    uint32_t data_buffer_count;
    uint32_t texture_buffer_count;
    uint32_t default_uniform_buffer_count;

    uint32_t literal_buffer_data_offset;

    uint32_t compiler_version; // The version is shifted 4 bits to the left.

    uint32_t literals_count;
    uint32_t literals_offset;
    uint32_t uniform_buffer_count;
    uint32_t uniform_buffer_offset;

    uint32_t dependent_sampler_count;
    uint32_t dependent_sampler_offset;
    uint32_t texture_buffer_dependent_sampler_count;
    uint32_t texture_buffer_dependent_sampler_offset;
    uint32_t container_count;
    uint32_t container_offset;
    uint32_t sampler_query_info_offset; // Offset to array of uint16_t

    SceGxmProgramType get_type() const {
        return static_cast<SceGxmProgramType>(program_flags & SCE_GXM_PROGRAM_FLAG_FRAGMENT);
    }
    bool is_vertex() const {
        return get_type() == SceGxmProgramType::Vertex;
    }
    bool is_fragment() const {
        return get_type() == SceGxmProgramType::Fragment;
    }
    OFFSET_FUNCTION(uint64_t, primary_program_start, primary_program_offset)
    OFFSET_FUNCTION(uint64_t, secondary_program_start, secondary_program_offset)
    OFFSET_FUNCTION(uint64_t, secondary_program_end, secondary_program_offset_end)
    bool is_discard_used() const {
        return (program_flags & SCE_GXM_PROGRAM_FLAG_DISCARD_USED);
    }
    bool is_depth_replace_used() const {
        return (program_flags & SCE_GXM_PROGRAM_FLAG_DEPTH_USED);
    }
    bool is_sprite_coord_used() const {
        return (program_flags & SCE_GXM_PROGRAM_FLAG_SPRITECOORD_USED);
    }
    bool is_native_color() const {
        return (program_flags & SCE_GXM_PROGRAM_FLAG_NATIVECOLOR_USED);
    }
    bool is_frag_color_used() const {
        return (program_flags & SCE_GXM_PROGRAM_FLAG_FRAGCOLOR_USED);
    }
    OFFSET_FUNCTION_CHECKED(SceGxmProgramParameter, program_parameters, parameters_offset)
    OFFSET_FUNCTION_CHECKED(SceGxmProgramVertexVaryings, vertex_varyings, varyings_offset)
    SceGxmParameterType get_fragment_output_type() const {
        return vertex_varyings()->output_param_type;
    }
    uint8_t get_fragment_output_component_count() const {
        return vertex_varyings()->output_comp_count;
    }
    bool is_secondary_program_available() const {
        return secondary_program_offset < secondary_program_offset_end + 4;
    }
    OFFSET_FUNCTION(uint8_t, literal_buffer_data, literal_buffer_data_offset)
    OFFSET_FUNCTION(SceGxmProgramLiteral, literals, literals_offset)
    OFFSET_FUNCTION(SceGxmUniformBufferInfo, uniform_buffer, uniform_buffer_offset)
    OFFSET_FUNCTION(SceGxmDependentSampler, dependent_sampler, dependent_sampler_offset)
    OFFSET_FUNCTION(SceGxmDependentSampler, texture_buffer_dependent_sampler, texture_buffer_dependent_sampler_offset)
    OFFSET_FUNCTION(SceGxmProgramParameterContainer, container, container_offset)
    // OFFSET_FUNCTION(uint8_t, sampler_query_info, sampler_query_info_offset)

    bool has_no_effect() const {
        return (program_flags & SCE_GXM_PROGRAM_FLAG_OUTPUT_UNDEFINED) && !is_discard_used() && !is_depth_replace_used();
    }
};

struct SceGxmProgramParameter {
    int32_t name_offset; // Number of bytes from the start of this structure to the name string.

    struct {
        // Each member is half a bit wide, so the values are [0-15], [0,F]
        SceGxmParameterCategory category : 4;
        SceGxmParameterType type : 4; // applicable for constants, not applicable for samplers (select type like float, half, fixed ...)
        uint8_t component_count : 4; // applicable for constants, not applicable for samplers (select size like float2, float3, float3 ...)
        uint8_t container_index : 4; // applicable for constants, not applicable for samplers (buffer, default, texture)
    };

    // Note, for uniform buffers, it looks like a semantic of 3 means it is being written to
    SceGxmParameterSemantic semantic; // applicable only for for vertex attributes, for everything else it's 0
    uint8_t semantic_index;
    uint32_t array_size;
    uint32_t resource_index;

    bool is_sampler_cube() const {
        return (semantic_index >> 4) & 1;
    }
    /**
     * \brief Returns raw parameter name
     *        Therefore, if parameter belongs in a struct, includes it in the form of "struct_name.field_name"
     */
    OFFSET_FUNCTION(char, name, name_offset)
};

static_assert(sizeof(SceGxmProgramParameter) == 16, "Incorrect structure layout.");

struct SceGxmVertexAttribute {
    uint16_t streamIndex;
    uint16_t offset;
    SceGxmAttributeFormat format;
    uint8_t componentCount;
    uint16_t regIndex; // Returned from sceGxmProgramParameterGetResourceIndex().
};

static_assert(sizeof(SceGxmVertexAttribute) == 8, "Structure has been incorrectly packed.");

enum {
    SCE_GXM_PRECOMPUTED_VERTEX_STATE_WORD_COUNT = 7,
    SCE_GXM_PRECOMPUTED_FRAGMENT_STATE_WORD_COUNT = 9,
    SCE_GXM_PRECOMPUTED_DRAW_WORD_COUNT = 11,
    SCE_GXM_MAX_UB_IN_FLOAT_UNIT = 2048 // Guessing
};
#undef OFFSET_FUNCTION
#undef OFFSET_FUNCTION_CHECKED
